import java.util.*;

public class MapText {
    static Scanner scanner = new Scanner(System.in);
    static HashMap<Integer,String> map = new HashMap<>();

    void show(){
        Collection<String> coll = map.values();
        Iterator<String> it = coll.iterator();
        System.out.print("当前歌曲列表：");
        while (it.hasNext()){
            System.out.print(it.next() + " ");
        }
        System.out.println();
    }
    void menu(){
        System.out.println("欢迎来到点歌系统!");
        System.out.println("********************");
        System.out.println("0.添加歌曲至列表");
        System.out.println("1.将歌曲置顶");
        System.out.println("2.将歌曲前移一位");
        System.out.println("3.退出");
        System.out.println("********************");
    }
    int Add(int id){
        id++;
        System.out.print("请输入要添加的歌曲名称：");
        String str =scanner.next();
        map.put(id,str);
        System.out.println("已添加歌曲：" + str);
        show();
        return id;
    }
    void Top(){
        System.out.print("请输入要置顶的歌曲名称：");
        String str = scanner.next();
        String str1 = map.get(1);
        int key = search(str);
        map.put(1,str);
        map.put(key,str1);
        System.out.println("已将歌曲" + str + "置顶");
        show();
    }
    void Move(){
        System.out.print("请输入要前移的歌曲名称：");
        String str = scanner.next();
        int key = search(str);
        String str1 = map.get(key-1);
        map.put(key-1,str);
        map.put(key,str1);
        System.out.println("已将歌曲" + str + "前移一位");
        show();

    }
    void out(){
        System.out.println("--------退出系统-------");
        System.out.println("您已退出系统");
        System.exit(0);
    }

    int search(String name){
        Set<Integer> set = map.keySet();
        Iterator<Integer> it = set.iterator();
        int key = 0;
        while (it.hasNext()){
            int f = it.next();
            if(name.equals(map.get(f))) key = f;
        }
        return key;
    }

    public static void main(String[] args) {
        map.put(1 ,"稻香");
        map.put(2 ,"夜曲");
        map.put(3 ,"夜的第七章");
        map.put(4 ,"听妈妈的话");
        map.put(5 ,"龙卷风");
        map.put(6 ,"一起学猫叫");
        int id = 6;
        MapText mapText = new MapText();
        int a = 10;
        while(a!=3)
        {
            mapText.menu();
            System.out.print("请输入要执行的操作序号：");
            a=scanner.nextInt();
            switch(a)
            {
                case 0:
                    id = mapText.Add(id);
                    break;
                case 1:
                    mapText.Top();
                    break;
                case 2:
                    mapText.Move();
                    break;
                case 3:
                    mapText.out();
                    break;
                default:break;
            }
        }
    }
}
